package com.cloudcc.mobile.view.test;

import android.content.Context;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.OnClick;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.util.VerificateUtils;

/**
 * 测试第一步骤 输入手机号码
 * 
 * @Description: TODO()
 * @author wangzhiqiang
 * @date 2016-3-2 下午3:34:30
 * 
 */
public class Step1Fragment extends BaseStepFragment {

	@Bind(R.id.test_done)
	Button btn_done;

	@Bind(R.id.test_et1)
	EditText et_test_phone;

	@Override
	public void init() {
		super.init();

		initEditText();
	}

	private void initEditText() {
		et_test_phone
				.setOnEditorActionListener(new EditText.OnEditorActionListener() {

					@Override
					public boolean onEditorAction(TextView v, int actionId,
							KeyEvent event) {
						if (actionId == EditorInfo.IME_ACTION_DONE) {
							InputMethodManager imm = (InputMethodManager) v
									.getContext().getSystemService(
											Context.INPUT_METHOD_SERVICE);
							imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
							clickDone();
							return true;
						}
						return false;
					}

				});
	}

	@OnClick(R.id.test_done)
	public void clickDone() {
		boolean isMobile = VerificateUtils.isMobile(et_test_phone.getText()
				.toString().trim());
		if (!isMobile) {
			Toast.makeText(mContext, "请输入正确的手机号", 0).show();
			return;
		}
		mParentActivity.resetSMSListener();
		mParentActivity.sendVerSMS(et_test_phone.getText().toString().trim());

	}

	@Override
	public int getLayoutId() {
		return R.layout.test_step1;
	}

}
